// packageB/pages/wangzhe/wangzhe.js
const app = getApp()
const INTERVAL = 10000;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    ggid: '',
    gglist: '',
    list:'',
    list1:'',
    page_no:1,
    tanchuang1:false,
    tanchuang11: false,
    interval: 2000,
    autoplay: true,
    interval: 2000,
    duration: 500,
  },
  z_kaihei5() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "id": wx.getStorageSync("guanjun")
    }
    wx.request({
      url: app.apiurl + 'api/wztzs/upWztzsTan',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          tanchuang11: false,
          tanchuang11_flag:false
        })
      }
    })
  },
  z_kaihei3() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/wztzs/tanChuangInfo',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.data != '') {
          _this.setData({
            xinxi: res.data.data
          })
            if(!_this.data.tanchuang11 && !_this.data.tanchuang11_flag){
              wx.setStorageSync("guanjun", res.data.data.id)
              wx.setStorageSync("guanjun_prize_id", res.data.data.prize_id)
              _this.setData({
                tanchuang11: true,
              })
            }
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    that.z_peizhi()
    that.timer = setInterval(function () {
      that.z_kaihei3()
    }, INTERVAL);
  },
  z_open(){
    this.setData({
      tanchuang1:true
    })
  },
  z_close(){
    this.setData({
      tanchuang1:false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_yonghu()
    this.z_jilu3()
    this.z_jilu()
    this.z_jilu1()
    this.z_kaihei3()
  },
  z_peizhi(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        let show_liaoliao = res.data.data.config_param55
        if(show_liaoliao == '1'){
          _this.setData({
            show_liaoliao_flag:true
          })
        }
      }
    })
  },
  z_yonghu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          _this.setData({
            login: true,
            yonghu: res.data.data
          })
        }
      }
    })
  },
  guanggao1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
        _this.setData({
          ggid: res.data.data[0].id
        })
        _this.guanggao2()
      }
    })
  },
  guanggao2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=19',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          gglist: res.data.data[0]
        })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  z_jilu3(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token")
    }
    wx.request({
      url: app.apiurl + 'api/config/unprizeList?fbwz_type=7',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          mylist:res.data.data
        })
      }
    })
   },
   z_jilu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/wztzs/tzsList',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          list: res.data.data
        })
      }
    })
  },
  z_jilu1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/wztzs/tzsRecordList?page_no=1&page_num=500',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
           _this.setData({
            list1: res.data.data.list
          })
        // if(_this.data.page_no == 1){
        //   _this.setData({
        //     list1: res.data.data.list
        //   })
        // } else {
        //   let list = _this.data.list1
        //   for(let i=0;i< res.data.data.list.length;i++){
        //     list.push(res.data.data.list[i])
        //   }
        //   _this.setData({
        //     list1: list
        //   })
        // }
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 //下滑刷新
 let _this = this
 let page_no  = _this.data.page_no
 page_no = page_no+1
 _this.setData({
   page_no:page_no
 })
 _this.z_jilu1()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})